#include <REGX52.H>

#define LED_PORT P2

sbit BTN_INC = P3 ^ 1;  
sbit BTN_DEC = P3 ^ 7;  

void delay_ms(unsigned int ms)
{
    unsigned int i, j;
    for (i = 0; i < ms; i++)
    {
        for (j = 0; j < 123; j++);
    }
}

void main()
{
    unsigned char counter = 0; 
    bit inc_pressed = 0;      
    bit dec_pressed = 0;      
    
    LED_PORT = ~counter;     

    while(1)
    {
        if (BTN_INC == 0 && !inc_pressed)
        {
            delay_ms(10); 
            if (BTN_INC == 0) 
            {
                inc_pressed = 1; 
                counter++;       
                LED_PORT = ~counter; 
            }
        }
        else if (BTN_INC == 1) 
        {
            inc_pressed = 0; 
        }

        if (BTN_DEC == 0 && !dec_pressed) 
        {
            delay_ms(10); 
            if (BTN_DEC == 0) 
            {
                dec_pressed = 1; 
                counter--;       
                LED_PORT = ~counter; 
            }
        }
        else if (BTN_DEC == 1) 
        {
            dec_pressed = 0; 
        }

        delay_ms(10);
    }
}